package com.gss.stockLedger.domain;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name="STK_TRNX_DTLS")
public class StockTransactionDtls extends CommonDetailsDTO implements Comparable<StockTransactionDtls>{

	
	private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
	
	//auto generated for primary key purpose
	private Long txnId;

	private String partId;	//0
	private String partDesc; //1
	private String sapDocNo; //2
	private String sapEntryDate; //3
	private String assignmentId; //4
	private String strTransactionDate; //5
	private Date transactionDate; 
	private String invoiceNo; //6
	private String strInvoiceDate; //7
	private String vendorCode; //8
	private String vendorName; //9
	private String inventoryType; //10
	private String transactionType; //11
	private String acctType; //12 
	private Long quantity; //13
	private Float rate; //14
	private Double value; //15
	private String purchaseType; //16
	private Double valueFCY; //17
	private String unitFCY; //18

	@Id 
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	@Column(name="TRNX_ID",nullable=false)
	public Long getTxnId() {
		return txnId;
	}
	
	@Column(name="TRNX_PART_ID",nullable=false,length=50)
	public String getPartId() {
		return partId;
	}
	
	@Column(name="TRNX_PART_DESC",length=150)
	public String getPartDesc() {
		return partDesc;
	}

	@Column(name="TRNX_SAP_DOCNO", length=50)
	public String getSapDocNo() {
		return sapDocNo;
	}

	@Column(name="TRNX_SAP_ENTRY_DATE", length=25)
	public String getSapEntryDate() {
		return sapEntryDate;
	}

	@Column(name="TRNX_ASSIGNMENT_ID",length=50)
	public String getAssignmentId() {
		return assignmentId;
	}

	@Transient
	public String getStrTransactionDate() {
		return strTransactionDate;
	}

	//@Column(name="TRNX_DATE")
	@Column(name="TRNX_RECEIPT_DATE")
	public Date getTransactionDate() {
		return transactionDate;
	}

	@Column(name="TRNX_INVOICE_NO",length=50)
	public String getInvoiceNo() {
		return invoiceNo;
	}
	
//	@Temporal(value=TemporalType.DATE)
	@Column(name="TRNX_INVOICE_DATE",length=25)
	public String getStrInvoiceDate() {
		return strInvoiceDate;
	}

	//@Column(name="TRNX_VENDOR_CODE",length=50)
	@Column(name="TRNX_VENDOR_ID")
	public String getVendorCode() {
		return vendorCode;
	}

	@Column(name="TRNX_VENDOR_NAME",length=150)
	public String getVendorName() {
		return vendorName;
	}

	@Column(name="TRNX_INV_TYPE",length=30)
	public String getInventoryType() {
		return inventoryType;
	}

	@Column(name="TRNX_TRNX_TYPE",length=50)
	public String getTransactionType() {
		return transactionType;
	}

	@Column(name="TRNX_ACTIVITY_TYPE",length=50)
	public String getAcctType() {
		return acctType;
	}

	@Column(name="TRNX_QUANTITY")
	public Long getQuantity() {
		return quantity;
	}

	@Column(name="TRNX_RATE",columnDefinition="float")
	public Float getRate() {
		return rate;
	}

	@Column(name="TRNX_VALUE",columnDefinition="double")
	public Double getValue() {
		return value;
	}

	@Column(name="TRNX_PURCHASE_TYPE",length=20)
	public String getPurchaseType() {
		return purchaseType;
	}

	@Column(name="TRNX_VALUE_FCY",columnDefinition="double")
	public Double getValueFCY() {
		return valueFCY;
	}

	@Column(name="TRNX_UNIT_FCY",length=20)
	public String getUnitFCY() {
		return unitFCY;
	}

	public void setPartId(String partId) {
		this.partId = partId;
	}

	public void setPartDesc(String partDesc) {
		this.partDesc = partDesc;
	}

	public void setSapDocNo(String sapDocNo) {
		this.sapDocNo = sapDocNo;
	}

	public void setSapEntryDate(String sapEntryDate) {
		this.sapEntryDate = sapEntryDate;
	}

	public void setAssignmentId(String assignmentId) {
		this.assignmentId = assignmentId;
	}

	public void setStrTransactionDate(String strTransactionDate) {
		this.strTransactionDate = strTransactionDate;
		try {
			transactionDate = dateFormat.parse(strTransactionDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}

	public void setInvoiceNo(String invoiceNo) {
		this.invoiceNo = invoiceNo;
	}

	public void setStrInvoiceDate(String invoiceDate) {
		this.strInvoiceDate = invoiceDate;
	}

	public void setVendorCode(String vendorCode) {
		this.vendorCode = vendorCode;
	}

	public void setVendorName(String vendorName) {
		this.vendorName = vendorName;
	}

	public void setInventoryType(String inventoryType) {
		this.inventoryType = inventoryType;
	}

	public void setTransactionType(String transactionType) {
		this.transactionType = transactionType;
	}

	public void setAcctType(String acctType) {
		this.acctType = acctType;
	}

	public void setQuantity(Long quantity) {
		this.quantity = quantity;
	}

	public void setRate(Float rate) {
		this.rate = rate;
	}

	public void setValue(Double value) {
		this.value = value;
	}

	public void setPurchaseType(String purchaseType) {
		this.purchaseType = purchaseType;
	}

	public void setValueFCY(Double valueFCY) {
		this.valueFCY = valueFCY;
	}

	public void setUnitFCY(String unitFCY) {
		this.unitFCY = unitFCY;
	}

	public void setTxnId(Long txnId) {
		this.txnId = txnId;
	}
	
	
	/*
	private Date assignmentDate;	
	private String grnId;	
	private Date receiptDate;
	private String uom;*/	
		
	@Override
	public int compareTo(StockTransactionDtls o) {
		
		if(this.getTransactionDate().after(o.getTransactionDate()))
		{
			return 1;
		}
		else
		return 0;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((txnId == null) ? 0 : txnId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		StockTransactionDtls other = (StockTransactionDtls) obj;
		if (txnId == null) {
			if (other.txnId != null)
				return false;
		} else if (!txnId.equals(other.txnId))
			return false;
		return true;
	}	
	
}
